package com.ruicar.afs.cloud.apply.business.service.impl;

import com.ruicar.afs.cloud.apply.business.service.ApplyAdminService;
import com.ruicar.afs.cloud.apply.common.feign.Apply2AdminFeign;
import com.ruicar.afs.cloud.apply.common.utils.ApplyConfig;
import com.ruicar.afs.cloud.common.core.security.vo.UserVo;
import com.ruicar.afs.cloud.common.core.util.IResponse;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

/**
 * @description: 进件授权服务
 * @author: sijun.yu
 * @date: 2020/8/31 21:26
 */
@Service
@AllArgsConstructor
public class ApplyAdminServiceImpl implements ApplyAdminService {

    private ApplyConfig config;
    private Apply2AdminFeign apply2AdminFeign;

    /**
     * 获取产品请求头
     *
     * @return
     */
    public Map makeCaseHeader() {
        Map<String, String> headers = new HashMap<>();
        headers.put("clientId", config.getAdminClientId());
        headers.put("clientSecret", config.getAdminClientSecret());
        return headers;
    }

    /**
     * 通过用户查询渠道ID
     * @param userId
     * @return
     */
    public IResponse getChannelIdByUsername(String userId){

        UserVo userVo = new UserVo();
        userVo.setUsername(userId);
        return apply2AdminFeign.getChannelIdByUsername(userVo,this.makeCaseHeader());
    }

    /**
     * 通过用户查询用户信息
     * @param userId
     * @return
     */
    @Override
    public IResponse getUserInfoByUsername(String userId){

        UserVo userVo = new UserVo();
        userVo.setUsername(userId);
        return apply2AdminFeign.getUserInfoByUsername(userVo,this.makeCaseHeader());
    }

    /**
     * 通过用户id获取用户身份证正面
     * @param userId
     * @return
     */
    @Override
    public IResponse getUserFileByUserId(String userId){

        UserVo userVo = new UserVo();
        userVo.setUsername(userId);
        return apply2AdminFeign.getUserFileByUserId(userVo,this.makeCaseHeader());
    }

}
